<template>
  <div v-if="isShow">
    <!-- sanku表格 -->
    <el-table
      ref="multipleTable"
      border
      fit
      :data="dataList"
      class="fixed"
      :row-key="getRowKeys"
      width="80%"
      height="240px"
    >
        <el-table-column
          label="序号"
          type="index"
          :index="1"
          width="50"
          align="center"
        ></el-table-column>
        <el-table-column
          label="配件id"
          prop="productId"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          label="配件名称"
          prop="productName"
          show-overflow-tooltip
        >
        </el-table-column>
        <!-- <el-table-column
          label="经销商名称"
          prop="supplierName"
          show-overflow-tooltip
        ></el-table-column> -->
         <el-table-column label="操作" width="90" v-if="title != '优惠券详情' ">
            <template slot-scope="scope">
              <el-button
                type="text"
                @click="del(scope.row)"
                >删除</el-button
              >
            </template>
          </el-table-column>
    </el-table>
  </div>
</template>

<script>
import {
  getSmsCouponListById,
} from '@/api/businessCo'
export default {
  name: "materialTable",
  props: {
    mtrId:{
     default:""
    },
    isShow:{
      type: Boolean,
      default: false
    },
    hasData:{
      type:Array,
      default: []
    },
    title:{
     default:""
    }
  },
  data() {
    return {
      // 获取表格row的key值
      getRowKeys(row) {
        return row.id;
      },
      dataList:[],
      pageInfo: {
        //分页数据
        size: 10,
        number: 1,
        totalElements: 0,
      },
    };
  },
  computed: {},
  created() {
    console.log(this.mtrId);
     this.getAlertList()
  },
  mounted() {
  },
  methods: {
    //获取工器具列表
    getAlertList(type) {
      this.listLoading = true; //列表加载状态
      if(type){
        this.dataList = this.hasData;
      }else{
        if(this.mtrId){
          getSmsCouponListById(this.mtrId).then((res) => {
            const {code = null,data=[],msg=""} = res.data;
            if (!code) {
              this.dataList = data.productRelationList
            } else {
              this.listLoading = false; //列表加载状态
              this.$message.error(msg);
            }
          });
        }
      }
    },
      //数组去重
    sortArray(arr, name) {
      let res = [];
      let obj = {};
      for (let i = 0; i < arr.length; i++) {
        if (!obj[arr[i][name]]) {
          // name  对应数组中的name
          res.push(arr[i]);
          obj[arr[i][name]] = true;
        }
      }
      return res;
    },
    //删除
    del(row){
      this.dataList.forEach((v, i) => {
        if (row.id === v.id) {
          this.dataList.splice(i, 1)
        }
      })
    },
    closeDialog(){
      this.$emit("update:isShow", false);
    },
     //切换分页
    handleChangePagination(page) {
      this.pageInfo.number = page;
      this.getAlertList();
    },
    //选择分页数
    handleSizeChange(val) {
      this.pageInfo.number = 1;
      this.pageInfo.size = val;
      this.getAlertList();
    },
    /**
     * 表示状态
     */
    tableRowClassName({ row, column, rowIndex, columnIndex }) {
      if (row.hasUnfinishedWorkOrder&&this.changeType == 1) {
        return "background: rgb(249,41,31,0.59) !important;";
      }
    },
  }
};
</script>

<style lang="scss" scoped>
.dialog {
  .textarea {
    ::v-deep .el-form-item__label {
      width: 120px !important;
    }
  }
}
</style>
